package ika.proj;

import ika.proj.Projection;
import java.awt.*;
import java.awt.geom.*;
import com.jhlabs.map.*;

/**
 * The Orthographic Azimuthal or Globe map projection.
 */
public class SimpleOrthographicAzimuthalProjection extends Projection {
    
    public SimpleOrthographicAzimuthalProjection() {
        initialize();
    }
    
    public Point2D.Double project(double lam, double phi, Point2D.Double xy) {
        // x = normalizeLongitude( (float)(lam-projectionLongitude) );
        boolean inside = minLongitude <= lam && lam <= maxLongitude;
        if (!inside) {
            xy.x = Double.NaN;
            xy.y = Double.NaN;
        } else {
            xy.y = Math.sin(phi);
            
            lam -= this.projectionLongitude;
            while (lam > MapMath.HALFPI)
                lam -= Math.PI;
            while (lam < -MapMath.HALFPI)
                lam += Math.PI;
            
            xy.x = Math.cos(phi) * Math.sin(lam);
        }
        return xy;
    }
    
    public String toString() {
        return "Simple Orthographic Azimuthal";
    }
    
}
